package xyz.kail.demo.consul.api.agent;

import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.agent.AgentConsulClient;
import com.ecwid.consul.v1.agent.model.Service;

import java.util.Map;
import java.util.Set;

/**
 * @author Kail
 * @since 2018/1/18.
 */
public class Main {

    public static void main(String[] args) {
        ConsulRawClient consulRawClient = new ConsulRawClient("localhost", 8511);
        AgentConsulClient agentConsulClient = new AgentConsulClient(consulRawClient);

        Response<Map<String, Service>> agentServices = agentConsulClient.getAgentServices();
        Map<String, Service> serviceMap = agentServices.getValue();
        Set<Map.Entry<String, Service>> entries = serviceMap.entrySet();

        for (Map.Entry<String, Service> entry : entries) {
            System.out.println(entry.getKey() + "--" + entry.getValue());
        }


    }

}
